<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<div style="height:100%; width:100%;">
    <table style=" height:100%; width:100%;border:1px;border-color:black">
        <tr>
            <td style="width:100%">
                <table style="height: 100%; width: 100%">
                    <tr style="height: 30%; border-bottom-width: 1px; border-bottom-color: gray; border-bottom-style: solid; height: 18em; ">
                        <td></td>
                        <td>
                            <div style="width: 100%">
                                <table style="width: 100%;line-height: 24px" class="form-table">
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label" style="width: 10%;">账&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号<span style=" color: red">*</span>:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtaccount" id="txtaccount" type="text">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码<span style=" color: red">*</span>:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtpassword" id="txtpassword" type="password">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">实&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名&nbsp;&nbsp;:</td>
                                        <td><input class="easyui-textbox" name="txtRealName" id="txtRealName" type="text"></td>

                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位&nbsp;&nbsp;:</td>
                                        <td><input class="easyui-textbox" name="txtjob" id="txtjob" type="text"></td>

                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;门&nbsp;&nbsp;:</td>
                                        <td><input id="txtdepartment"></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色&nbsp;&nbsp;:</td>
                                        <td><input name="ddlroles" id="ddlroles"></td>
                                    </tr>

                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">入职时间&nbsp;&nbsp;:</td>
                                        <td><input name="user_join_day" id="user_join_day" type="text" class="easyui-datebox"></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">手&nbsp;机&nbsp;号&nbsp;&nbsp;:</td>
                                        <td><input name="user_mobile" id="user_mobile" type="number" class="easyui-textbox"></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">籍&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;贯&nbsp;&nbsp;:</td>
                                        <td><input name="user_birthplace" id="user_birthplace" type="text" class="easyui-textbox"></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">英&nbsp;文&nbsp;名&nbsp;&nbsp;:</td>
                                        <td><input name="user_enname" id="user_enname" type="text" class="easyui-textbox"></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别&nbsp;&nbsp;:</td>
                                        <td>男 <input name="user_sex" type="radio" checked="checked" value="0" />    女 <input name="user_sex" type="radio" value="1" /></td>
                                    </tr>

                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label">可&nbsp;登&nbsp;录&nbsp;&nbsp;:</td>
                                        <td>是 <input id="radioUserTrue" name="radioUserTrue" type="radio" checked="checked" value="1" onchange="radioUserCheck(1)" />    否 <input id="radioUserFalse" name="radioUserFalse" type="radio" value="0" onchange="radioUserCheck(0)" /></td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label" style="width: 10%;">工&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号:</td>
                                        <td>
                                            <input class="easyui-textbox" name="txtUserNo" id="txtUserNo" type="text">
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="form-label"></td>
                                        <td class="form-label"></td>
                                        <td>
                                            <div id="divpower">
                                                <a href="javascript:saveUserData()" class="easyui-linkbutton" style=" width:80px" id="btnSave">保存</a>
                                            </div>
                                        </td>
                                    </tr>

                                </table>
                            </div>
                        </td>
                        <td></td>
                    </tr>
                </table>
            </td>
        </tr>

    </table>
</div>
<script src="<%=basePath%>/Scripts/md5.js"></script>
<script type="text/javascript">

    $(function () {
        $('#ddlroles').combobox({
            multiple: true,
            url: '<%=basePath%>/system/role/getAllRoles',
            valueField: 'roleId',
            textField: 'name'
        });
        $('#txtdepartment').combotree({
            url: '<%=basePath%>/system/department/getDepartmentTreeData',
            width: '20%',
            loadFilter: function (rows) {
            	debugger
                return convert(rows);
            }
        });
    });
    function radioUserCheck(radiovalue) {
        if (radiovalue == 1) {
            $("#radioUserTrue").attr("checked", "checked");
            $("#radioUserFalse").attr("checked", false);
        }
        else {
            $("#radioUserFalse").attr("checked", "checked");
            $("#radioUserTrue").attr("checked", false);
        }
    }

    var radioValue = "0";
    var radioSexValue = "0";
    function saveUserData() {
        if ($("#txtaccount").val().trim() == "") {
            ERP_alert("账号不能为空!");
            return;
        }
        if ($("#txtpassword").val().trim() == "") {
            ERP_alert("密码不能为空!");
            return;
        }
        if ($('input:radio[name="radioUserTrue"]').is(":checked") == true) {
            radioValue = "1";
        }
        else {
            radioValue = "0";
        }

        var txtUserNo = $("#txtUserNo").val().trim()
        if (txtUserNo == "") {
            ERP_alert("工号不能为空!");
            return;
        }

        var postdata = {
            account: $("#txtaccount").val().trim(),
            password: MD5($("#txtpassword").val().trim()),
            realname: $("#txtRealName").val().trim(),
            job: $("#txtjob").val().trim(),
            IsLogin: radioValue,
            depart: $('#txtdepartment').combotree('getValue'),
            role: $('#ddlroles').combobox('getValues').join(','),

            user_join_day: $('#user_join_day').datebox('getValue'),
            user_mobile: $('#user_mobile').val().trim(),
            user_birthplace: $('#user_birthplace').val().trim(),
            user_enname: $('#user_enname').val().trim(),
            user_sex: $('input[name="user_sex"]:checked').val(),
            txtUserNo: txtUserNo,
        };

        $.post("<%=basePath%>/system/user/saveUserData", postdata, function (data) {
            if (data == "") {
                ERP_alert('保存成功');
                intCon();
            }
            else {
                ERP_alert(data);
            }
        });
    }

    function intCon() {
        $("#txtaccount").textbox('setValue', "");
        $("#txtpassword").textbox('setValue', "");
        $("#txtRealName").textbox('setValue', "");
        radioUserCheck(1);
    }
</script>


